# -*- coding: utf-8 -*-
# Author: xiantingDeng
# File: 03_深拷贝-浅拷贝.py
# Time: 21:28

# import copy
#
# a = [1, 2, 3, 4, 5, ['a', 'b']]
# # 原始对象
# b = a  # 赋值，传对象的引用
# c = copy.copy(a)  # 对象拷贝，浅拷贝
# d = copy.deepcopy(a)  # 对象拷贝，深拷贝
# print("a=", a, "    id(a)=", id(a), "id(a[5])=", id(a[5]))
# print("b=", b, "    id(b)=", id(b), "id(b[5])=", id(b[5]))
# print("c=", c, "    id(c)=", id(c), "id(c[5])=", id(c[5]))
# print("d=", d, "    id(d)=", id(d), "id(d[5])=", id(d[5]))
# print("*" * 70)
#
# a.append(6)  # 修改对象a)
# a[5].append('c')  # 修改对象a中的['a','b']数组对象)
# print("a=", a, "    id(a)=", id(a), "id(a[5])=", id(a[5]))
# print("b=", b, "    id(b)=", id(b), "id(b[5])=", id(b[5]))
# print("c=", c, "       id(c)=", id(c), "id(c[5])=", id(c[5]))
# print("d=", d, "            id(d)=", id(d), "id(d[5])=", id(d[5]))


# 按照自己的理解：
# 浅拷贝，拷贝的地址是不一样的 但是里面的可变的内容（如：list dict）还是指向的同一个地址，
# 也就是说如果被拷贝更改了数据还是会影响到拷贝的对象数据（藕断丝连）
# 深拷贝，拷贝的地址不一样，且数据内不管可变与不可变的地址都会重新申请不在是同一个地址，
# 相当于之前的被拷贝数据就算更改也和拷贝对象无任何关系，相当于两个数据完全一样但是地址不同的数据，相当于离婚了
# 浅拷贝对一个对象的顶层拷贝
#
# a = [11,22,33]
#
# b = a
#
# print(id(a))
# print(id(b))
#
# # 深拷贝
# import copy
#
# c = copy.deepcopy(a)
# print(id(a))
# print(id(c))
import copy

# a = [11,22,33]
# b = [44,55,66]
#
# c = [a,b]
# e = copy.deepcopy(c)
# a.append(99)
# print(id(a))
# print(id(c))
# print(id(e))
# print(c)
# print(e)

#
#
# print(bin(18))
# b = 0b10010
# print(b)

import copy
a = [1,2,3,[4,5]]

b = a

c = copy.deepcopy(b)

a[3].append(6)
print(id(a))
print(id(b))
print(id(c))
print(a)
print(b)
print(c)